package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/22 22:57
 **/
public class Day37_2_Num86_Partition {
    class Solution {
        public ListNode partition(ListNode head, int x) {
            ListNode dummyHead1 = new ListNode(-1);
            ListNode dummyHead2 = new ListNode(-1);
            ListNode node1 = dummyHead1;
            ListNode node2 = dummyHead2;

            while(head != null){
                if(head.val < x){
                    node1.next = head;
                    head = head.next;
                    node1 = node1.next;
                    node1.next = null;
                }else {
                    node2.next = head;
                    head = head.next;
                    node2 = node2.next;
                    node2.next = null;
                }
            }
            node1.next = dummyHead2.next;
            return dummyHead1.next;
        }
    }
}